package cn.distribution.personManager.service;

import cn.distribution.personManager.entity.dao.PersonManagerDAO;
import cn.distribution.personManager.entity.vo.PersonExportVO;
import cn.distribution.personManager.entity.vo.PersonManagerVO;
import cn.distribution.personManager.mapper.PersonManagerMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xiayujia
 */
@Service
public class PersonManagerService extends ServiceImpl<PersonManagerMapper, PersonManagerDAO>  {

    @Resource
    private PersonManagerMapper personManagerMapper;

    /**
     * 通过群号用户身份得到用户id
     * @author zhengminjie
     */
    public List<Long> getUserIdByNum(Long groupNum, String userIdentity){
        return this.personManagerMapper.getUserIdByNum(groupNum, userIdentity);
    }

    /**
     * 得到成员个数
     * @author zhengminjie
     * @return 个数
     */
    public Integer countNumber(){return this.personManagerMapper.countNumber();};
    /**
     *  @author xiayujia
     * 通过群id得到群号
     */
    public Long getNumById(Long groupId){
        return personManagerMapper.getNumById(groupId);
    }

    /**
     * 通过群id用户id得到所有信息
     * @author zhengminjie
     */
    public PersonManagerVO getAllById(Long groupId, Long userId){
        return personManagerMapper.getAllById(groupId, userId);
    }
    /**
     * 通过群id用户名得到用户id
     * @author xiayujia
     */
    public Long getUserIdByIdName(Long groupId,String userName){
        return this.personManagerMapper.getUserIdByIdName(groupId, userName);
    }

    /**
     * 通过群id用户在群内的昵称得到用户id
     * @author xiayujia
     */
    public Long getUserIdByIdGroupName(Long groupId,String groupUserName){
        return this.personManagerMapper.getUserIdByIdGroupName(groupId,groupUserName);
    }

    /**
     *  通过群id和用户id得到列表
     * @author xiayujia
     * */
    public List<PersonManagerVO> getListById(Long groupId, Long userId ,String userIdentity){
        return this.personManagerMapper.getListById(groupId,userId,userIdentity);
    }

    /**
     *  通过群id得到成员列表
     * @author xiayujia
     * */
    public List<PersonManagerVO> searchMember(Long groupId, Long userId,String userIdentity){
        return this.personManagerMapper.searchMember(groupId,userId,userIdentity);
    }

    /**
     * 通过群号和用户id得到用户身份
     * @author zhengminjie
     */
    public String getIdentityByNum(Long groupNum,Long userId){
        return this.personManagerMapper.getIdentityByNum(groupNum, userId);
    }

    /**
     * 通过群号删除所有和这个群有关的
     * @author zhengminjie
     */
    public Long deleteAllGroup(Long groupNum){
        return this.personManagerMapper.deleteAllGroup(groupNum);
    }

    /**
     * 通过群号和用户id删除某项
     * @author zhengminjie
     */
    public Long deleteGroup(Long groupNum,Long userId){
        return this.personManagerMapper.deleteGroup(groupNum, userId);
    }

    /**
     * 通过群号和用户id删除某成员
     * @author xiayujia
     */
    public Long deleteMember(Long groupId,Long userId){
        return this.personManagerMapper.deleteMember(groupId, userId);
    }

    /**
     * 通过群id和用户编号查看是否有数据
     * @author zhengminjie
     */
    public Long getIfSame(PersonManagerDAO personManagerDAO){
        return this.personManagerMapper.getIfSame(personManagerDAO);
    }

    /**
     * 通过群id和用户id查看是否有数据
     *  @author zhengminjie
     */
    public Long getIfExist(Long groupid, Long userid){
        return this.personManagerMapper.getIfExist(groupid,userid);
    }

    /**
     * 通过群id和用户id更新表
     * @author zhengminjie
     */
    public Long updateNumber(PersonManagerDAO personManagerDAO){
        return this.personManagerMapper.updateNumber(personManagerDAO);
    }

    /**
     * 通过群id和用户id更新群用户身份权限
     * @author xiayujia
     */
    public Long updateIdentiDistri(Long groupId,Long userId,String userIdentity,Boolean dataDistribution){
        return this.personManagerMapper.updateIdentiDistri(groupId,userId,userIdentity,dataDistribution);
    }

    /**
     * 通过群id和用户id更新群用户群昵称用户身份编号
     * @author xiayujia
     */
    public Long updateInfo(Long groupId,Long userId,String groupUserName,Long userNumber){
        return this.personManagerMapper.updateInfo(groupId,userId,groupUserName,userNumber);
    }

    /**
     * 导出名单
     * @author zhengminjie
     */
    public List<PersonExportVO> exportMember(Long groupId){
       return this.personManagerMapper.exportMember(groupId);
    }
}
